<?php

namespace App\Observers;

use App\Models\News;
use App\Models\NewsLike;

class NewsLikeObserver
{

    /**
     * 监听创建前事件.
     *
     * @param NewsLike $model
     * @return void
     */
    public function creating(NewsLike $model)
    {

    }

    /**
     * 监听创建事件.
     *
     * @param NewsLike $model
     * @return void
     */
    public function created(NewsLike $model)
    {
        News::where('id', $model->news_id)->increment('like_amount');
    }

    public function updating(NewsLike $model)
    {

    }

    /**
     * 监听更新后事件.
     *
     * @param NewsLike $model
     * @return void
     */
    public function updated(NewsLike $model)
    {

    }

    /**
     * 监听删除事件.
     *
     * @param NewsLike $model
     * @return void
     */
    public function deleting(NewsLike $model)
    {

    }

    /**
     * 监听删除事件.
     *
     * @param NewsLike $model
     * @return void
     */
    public function deleted(NewsLike $model)
    {
        News::where('id', $model->news_id)->decrement('like_amount');
    }

}
